package com.ch.engine.daily.valid;

import com.ch.common.result.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 客户web接口
 *
 * @author wangchunhui
 * @date 2024/8/15 17:43
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/account")
@Slf4j
@Validated
public class AccountController {

    /**
     * 测试参数校验
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @PostMapping("/v1")
    public Result v1(@RequestBody @Validated(value = Account.V1.class) Account account) {
        return Result.SUCCESS(account.getName());
    }

    /**
     * 测试参数校验
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @PostMapping("/v2")
    public Result v2(@RequestBody @Validated(value = Account.V2.class) Account account) {
        return Result.SUCCESS(account.getName());
    }

    /**
     * 测试参数校验（没有指定组别，参数校验不生效）
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @PostMapping("/v3")
    public Result v3(@RequestBody @Validated Account account) {
        return Result.SUCCESS(account.getName());
    }

    /**
     * 测试参数校验
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @PostMapping("/v4")
    public Result v4(@RequestBody @Validated AccountList accountList) {
        return Result.SUCCESS(accountList.getAccounts());
    }

    /**
     * 测试参数校验
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @PostMapping("/v5")
    public Result v5(@RequestBody @Valid List<AccountDTO> accountList) {
        return Result.SUCCESS();
    }
}
